<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class m_statistics extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_banseinfo($sTime,$eTime,$start=0,$len=15) {
        $str = " WHERE 1=1 ";
        if($sTime){
        	$str .= " AND regtime>".$sTime;
        }
        if($eTime){
        	$str .= " AND regtime<".$eTime;
        }
        $sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(regtime),'%Y-%m-%d') as udate ,count(DATE_FORMAT(FROM_UNIXTIME(regtime),'%Y-%m-%d')) as number FROM `u_banseinfo`";
        $sql .= $str." GROUP BY DATE_FORMAT(FROM_UNIXTIME(regtime),'%Y-%m-%d') ORDER BY DATE_FORMAT(FROM_UNIXTIME(regtime),'%Y-%m-%d') DESC  limit 30";
        //$sql .= " LIMIT $start,$len";
       // print_r($sql);
        $result = $this->db->query($sql)->result_array();
        return $result;
    }

    function get_message($sTime,$eTime,$start=0,$len=30){
		$str = " WHERE 1=1 ";
        if($sTime){
        	$str .= " AND mtime>".$sTime;
        }
        if($eTime){
        	$str .= " AND mtime<".$eTime;
        }
        $sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') as udate ,count(DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d')) as number FROM `u_message`";
        $sql .= $str." GROUP BY DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') ORDER BY DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') DESC   limit 30";
        $result = $this->db->query($sql)->result_array();
        return $result;
    }
    
    function get_message_bak($sTime,$eTime,$start=0,$len=15){
    	$str = " WHERE 1=1 ";
        if($sTime){
        	$str .= " AND mtime>".$sTime;
        }
        if($eTime){
        	$str .= " AND mtime<".$eTime;
        }
        $sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') as udate ,count(DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d')) as number FROM `u_message_bak`";
        $sql .= $str." GROUP BY DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') ORDER BY DATE_FORMAT(FROM_UNIXTIME(mtime),'%Y-%m-%d') DESC   limit ".$len;
        $result = $this->db->query($sql)->result_array();
        return $result;
    }

    function get_pro($sTime,$eTime,$start=0,$len=15){
		$str = " WHERE 1=1 ";
        if($sTime){
        	$str .= " AND create_time>".$sTime;
        }
        if($eTime){
        	$str .= " AND create_time<".$eTime;
        }
        $sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d') as udate ,count(DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d')) as number FROM `u_pro`";
        $sql .= $str." GROUP BY DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d') ORDER BY DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d') DESC  limit 30";
        $result = $this->db->query($sql)->result_array();
        return $result;
    }

    function get_banseinfo_count(){
    	return $this->db->count_all('u_banseinfo');
    }

    function get_message_count(){
    	return $this->db->count_all('u_message');
    }
    
	function get_message_bak_count(){
    	return $this->db->count_all('u_message_bak');
    }

    function get_pro_count(){
    	return $this->db->count_all('u_pro');
    }

    function get_friend_count(){
    	return $this->db->count_all('u_friend')/2;
    }
}

?>